class Task
  attr_reader :name, :parent
  
  def initialize(name)
    @name = name
    @parent = nil
  end
  
  def get_time_required
    0.0
  end
  
  def total_number_basic_tasks
    1
  end
end

class CompositeTask < Task
  
  def initialize(name)
    super(name)
    @sub_tasks = []
  end
  
  def add_sub_task(task)
    @sub_tasks << task
    task.parent = self
  end
  
  def <<(task)
    add_sub_task(task)
  end
  
  def [](index)
    @sub_tasks[index]
  end
  
  def []=(index, new_value)
    @sub_tasks[index] = new_value
  end
  
  def remove_sub_task(task)
    @sub_tasks.delete(task)
    task.parent = nil
  end
  
  def get_time_required
    @sub_tasks.inject(0.0) { | time, task | time + task.get_time_required }
  end
  
  def total_number_basic_tasks
    @sub_tasks.inject(0) { | total, task | total + task.total_number_basic_tasks }
  end
end

class AddDryIngredientsTask < CompositeTask
  def initialize
    super("Add dry Ingredients.")
  end
  
  def get_time_required
    1.0
  end
end

class AddLiquidsTask < CompositeTask
  def initialize
    super("Add liquids.")
  end
  
  def get_time_required
    1.0
  end
end

class MixTask < CompositeTask
  def initialize
    super("Mix that batter up!")
  end
  
  def get_time_required
    3.0
  end
end

